package com.kds.changzhou.handler;

import com.kds.changzhou.message.inbound.AbstractInboundMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @author 孔德嵩
 */
@Slf4j
public class XmlDecoder extends MessageToMessageDecoder {


    @Override
    protected void decode(ChannelHandlerContext ctx, Object msg, List out) throws Exception {

        /**
         * xml字符串
         */
        String str = (String) msg;
        AbstractInboundMessage message = handlerConfig.getInBoundMessageFactory().buildInboundMessage(str);
        out.add(message);


    }

    private HandlerConfig handlerConfig;

    public XmlDecoder(HandlerConfig handlerConfig) {
        this.handlerConfig = handlerConfig;
    }
}
